package thread;

//懒汉模式实现单例模式
class SingletonLazy {
    //这个引用指向唯一实例, 先初始化为null , 而不是立即调用实例
    private static SingletonLazy instance = null;

    public static SingletonLazy getInstance() {
        if(instance == null) {
            instance = new SingletonLazy();
        }
        return instance;
    }

    private SingletonLazy() {};
}
public class ThreadDemo27 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getInstance();
        SingletonLazy s2 = SingletonLazy.getInstance();
        System.out.println(s1 == s2);
    }
}
